home *** CD-ROM | disk | FTP | other *** search
/ Aminet 41 / Aminet 41 (2001)(Schatztruhe)[!][Feb 2001].iso / Aminet / comm / tcp / rxsocket.lha / rxsocket / examples / rxresolve.rexx < prev    next >
OS/2 REXX Batch file  |  2000-11-28  |  2KB  |  84 lines

  1. /*
  2.     rxresolve: just like miamiresolve
  3.  
  4.     Usage: rxresolve <host>
  5.            rxresolve -s <servicename>
  6. */
  7.  
  8. l="rexxsupport.library";if ~show("L",l) then;if ~addlib(l,0,-30) then do;say "can't find" l;exit;end
  9. l="rmh.library";if ~show("L",l) then;if ~addlib(l,0,-30) then do;say "can't find" l;exit;end
  10. l="rxsocket.library";if ~show("L",l) then;if ~addlib(l,0,-30) then do;say "can't find" l;exit;end
  11.  
  12. parse arg host "-s" serv .
  13.  
  14. if host="" then
  15.     if serv="" then call usage()
  16.     else call findServ(serv)
  17. else
  18.     if host="?" then call usage()
  19.     else call findHost(host)
  20.  
  21. /****************************************************************************/
  22.  
  23. Usage: PROCEDURE
  24.     say "Usage: rxresolve host"
  25.     say "       rxresolve -s servicename"
  26.     exit
  27.  
  28. /****************************************************************************/
  29.  
  30. findServ: PROCEDURE
  31. parse arg serv
  32.  
  33.     if DataType(serv,NUM) then res = GetServByPort("SERV",serv,"tcp")
  34.     else res = GetServByName("SERV",serv,"tcp")
  35.  
  36.     if ~res then do
  37.         say "Service <" || serv || "> not found."
  38.         exit
  39.     end
  40.  
  41.     say "service:" serv.servname
  42.  
  43.     if serv.servaliases.num~=0 then do
  44.         say "aliases:"
  45.         do i = 0 to serv.servaliases.num-1
  46.             say "   " serv.servaliases.i
  47.         end
  48.     end
  49.  
  50.     say "port:" serv.servport
  51.  
  52.     exit
  53.  
  54. /****************************************************************************/
  55.  
  56. findHost: PROCEDURE
  57. parse arg host
  58.  
  59.     if IsDotAddr(host) then res = GetHostByAddr("HE",host)
  60.     else res = GetHostByname("HE",host)
  61.  
  62.     if ~res then do
  63.         say "Host <" || host || "> not found (" || HostErrorstring() || ")."
  64.         exit
  65.     end
  66.  
  67.     say "host:" he.hostname
  68.  
  69.     if he.hostaliases.num ~= 0 then do
  70.         say "aliases:"
  71.         do i = 0 to he.hostaliases.num-1
  72.             say "   " he.hostaliases.i
  73.         end
  74.     end
  75.  
  76.     say "address list:"
  77.     do i = 0 to he.hostaddrlist.num-1
  78.         say "   " he.hostaddrlist.i
  79.     end
  80.  
  81.     exit
  82.  
  83. /****************************************************************************/
  84.